package com.syb.controller.function;


import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.syb.entity.function.SysResource;
import com.syb.service.ResourceService;
import com.syb.util.PageResults;

@Namespace("/resources")
public class ResourcesController extends ActionSupport{

	private static Logger logger = Logger.getLogger(ResourcesController.class);
	
	@Autowired
	private ResourceService resouceService;
	

	private Integer currentPage;
	
	private String name;
	
	@Action(value="getResorcesList",results={
			@Result(name="success",location="/jsp/background/resources/list.jsp"),
			@Result(name="error",location="/error.jsp")
			})
	public String getResoucesList(){
		PageResults<SysResource> resourceList = new PageResults<SysResource>();
		PageResults<SysResource> page = new PageResults<SysResource>();
		if(name!=null&&name.length()>0){
			page.getParamMap().put("name", name);
		}
		if(currentPage!=null&&!currentPage.equals("")){
			page.setCurrentPage(currentPage);
		}
		try{
			resourceList = resouceService.findSysResourcesList(page);
		}catch(Exception e){
			logger.error(e.getMessage());
			ActionContext.getContext().put("error", e.getMessage());
			return "error";
		}
		ActionContext.getContext().put("result", resourceList);
		return "success";
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
	
	
	
}
